#include<iostream>
#include<string>
#include<queue>
#include<math.h>
using namespace std;
typedef struct node *BTree;
typedef struct node{
	char data;
	BTree lchild;
	BTree rchild;
	int h; 
}TNode;
BTree CreateBTree(string str,int i)
{
   int len;
   BTree bt;
   bt=new TNode;
   len=str.size();
   if(i>len-1 || i<=0) return NULL;
   if(str[i]=='#') return NULL;
   bt->data =str[i];
   bt->h=log(i)/log(2)+1;
   bt->lchild =CreateBTree(str,2*i); 
   bt->rchild =CreateBTree(str,2*i+1); 	
   return bt;
}
static int L=0;
int wpl(BTree bt){
	if(bt==NULL)return 0;
	if(bt->lchild==NULL&&bt->rchild==NULL){
		L+=(bt->data-'0')*(bt->h-1);
	}
	if(bt->lchild)wpl(bt->lchild);
	if(bt->rchild)wpl(bt->rchild);
	return L;
}
int main(){
	string str;
	cin>>str;
	if(str[1]==0){
		cout<<0;return 0;
	}
	BTree bt=CreateBTree(str,1);
	cout<<wpl(bt);
	return 0;
} 
